<%@page import="helpers.DateHelper"%>
<%@page import="models.GeoModel"%>
<%@page import="java.util.Map"%>
<%@page import="models.DealEmailModel"%>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="helpers.PaginatorHelper"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="java.util.ArrayList"%>
<%
Map<String, GeoModel> cities = (Map<String, GeoModel>) request.getAttribute("cities");
ArrayList<DealEmailModel> deals = (ArrayList<DealEmailModel>) request.getAttribute("deals");
int pages = (Integer) request.getAttribute("page");
boolean nextPage = (Boolean) request.getAttribute("nextPage");
boolean prevPage = (Boolean) request.getAttribute("prevPage");
PaginatorHelper paginator = (PaginatorHelper) request.getAttribute("paginator");
%>

<jsp:include page="/admin/layouts/header.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>

<script type="text/javascript" src="/admin/js/list_deal_email.js"></script>
<script type="text/javascript" src="/admin/js/list_form.js"></script>
<script type="text/javascript">
<!--
var server = "<%=UrlHelper.getServerUrl(request)%>";
//-->
</script>
        <div class="maincontent noright">
        	<div class="maincontentinner">
            	
                <ul class="maintabmenu">
                	<li class="current"><a href="/admin/dealsemail/list">Danh sách Deal Email</a></li>
                	<li><a href="/admin/dealsemail/create">Tạo Deal Email</a></li>
                </ul><!--maintabmenu-->
                
                <div class="content">
                	<jsp:include page="/admin/elements/message.jsp"/>
                
                	<div class="contenttitle radiusbottom0">
	                	<h2 class="table"><span>Danh sách Deal Email</span></h2>
	                </div>
	                
	                <table cellspacing="0" cellpadding="0" border="0" class="stdtable stdtablecb" id="list-table">
	                    <colgroup>
	                        <col class="con0">
	                        <col class="con1">
	                        <col class="con0">
	                        <col class="con1">
	                        <col class="con0">
	                        <col class="con1">
	                        <col class="con0">
	                    </colgroup>
	                    <thead>
	                        <tr>
	                        	<th class="head0"><span class="checkbox"><input type="checkbox" class="checkall"></span></th>
	                            <th class="head1">Id</th>
	                            <th class="head0">Ngày tạo</th>
	                            <th class="head1">Tỉnh/Thành phố</th>
	                            <th class="head0">Tiêu đề</th>
	                            <th class="head1">Trạng thái</th>
	                            <th class="head0">Thao tác</th>
	                        </tr>
	                    </thead>
	                    <tfoot>
	                        <tr>
	                        	<th class="head0"><span class="checkbox"><input type="checkbox" class="checkall"></span></th>
	                            <th class="head1">Id</th>
	                            <th class="head0">Ngày tạo</th>
	                            <th class="head1">Tỉnh/Thành phố</th>
	                            <th class="head0">Tiêu đề</th>
	                            <th class="head1">Trạng thái</th>
	                            <th class="head0">Thao tác</th>
	                        </tr>
	                    </tfoot>
	                    <tbody>
	                    	<% for (int i = 0; i < deals.size(); i++) { %>
	                        <tr>
	                        	<td class="center"><span class="checkbox"><input type="checkbox" value="<%=deals.get(i).getId()%>"></span></td>
	                            <td class="center"><%=deals.get(i).getId() %></td>
	                            <td class="center"><%=DateHelper.dateToString(deals.get(i).getDate(), "dd-MM-yyyy hh:mm")  %></td>
	                            <td class="center"><%=cities.get(deals.get(i).getCity()) != null ? cities.get(deals.get(i).getCity()).getName() : ""  %></td>
	                            <td class="center"><%=deals.get(i).getTitle() %></td>
	                            <td class="center"><%=deals.get(i).isSended()==true ? "Đã gửi email" : "Chưa gửi email" %></td>
	                            <td class="center">
	                            	<a title="Xem trước" href="/print/dealsemail/preview/<%=deals.get(i).getId()%>" id="action_preview" class="preview" target="_blank">
										Xem
									</a>&nbsp;&nbsp;&nbsp;
									<% if (!deals.get(i).isSended()) { %>
									<a title="Gửi email" href="/admin/dealsemail/sendemail/<%=deals.get(i).getId()%>" id="action_send" class="send">
										Gửi email
									</a>&nbsp;&nbsp;&nbsp;
									<a title="Xóa" href="/admin/dealsemail/delete/<%=deals.get(i).getId()%>" id="action_del" class="delete">
										Xóa
									</a>
									<% } %>
								</td>
	                        </tr>
	                        <% } %>
	                    </tbody>
	                </table>
	                <!-- paginate -->
	                <div class="dataTables_paginate paging_full_numbers" id="dyntable_paginate">
	                	<% if (prevPage) { %>
							<a class="previous paginate_button" id="dyntable_previous" href="<%=paginator.getPrev()%>">Trang trước</a>
						<% } else { %>
							<span class="previous paginate_button paginate_button_disabled" id="dyntable_previous">Trang trước</span>
						<% } %>
						<% if (nextPage) { %>
							<a class="next paginate_button" id="dyntable_next"  href="<%=paginator.getNext()%>">Trang tiếp</a>
						<% } else { %>
							<span class="next paginate_button paginate_button_disabled" id="dyntable_next">Trang tiếp</span>
						<% } %>
	                </div>
                </div><!--content-->
                
            </div><!--maincontentinner-->
            
            <jsp:include page="/admin/elements/copyright.jsp">
            	<jsp:param name="language" value="1" />
			</jsp:include>
            
        </div><!--maincontent-->
        
<jsp:include page="/admin/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>